package com.lzs.bootsafety.common.util;

import com.lzs.bootsafety.business.sys.entity.SysDept;
import com.lzs.bootsafety.business.sys.entity.SysDeptTree;
import com.lzs.bootsafety.business.sys.entity.SysMenu;

import java.util.ArrayList;
import java.util.List;

public class DeptTree {
    public  static List<SysDept> buildTree(List<SysDept> nodes, Long dept_Id){
        List<SysDept> sysDepts = new ArrayList<SysDept>();
        for (SysDept sysDept: nodes) {
            if (dept_Id == sysDept.getParentId()){
                sysDept.setChildren(buildTree(nodes,sysDept.getDeptId()));
                sysDepts.add(sysDept);
            }
        }
        return sysDepts;
    }

    public  static List<SysDeptTree> buildTrees(List<SysDeptTree> sysDeptTrees, Long dept_Id){
        List<SysDeptTree> list = new ArrayList<>();
        sysDeptTrees.forEach((item)->{
            if(dept_Id==item.getParentId()){
                item.setChildren(buildTrees(sysDeptTrees,item.getId()));
                list.add(item);
            }
        });
        return list;
    }
}
